<template>
  <div class="app-container">
    <div v-if="user">
      <el-row :gutter="20">
        <el-col :span="6" :xs="24">
          <user-card :user="user" />
        </el-col>
        <el-col :span="18" :xs="24">
          <el-card>
            <el-tabs v-model="activeTab">
              <el-tab-pane label="修改资料" name="userinfo">
                <userinfo />
              </el-tab-pane>
              <el-tab-pane label="修改密码" name="account">
                <account />
              </el-tab-pane>
            </el-tabs>
          </el-card>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import UserCard from './components/usercard'
import Account from '@/views/profile/components/account'
import Userinfo from '@/views/profile/components/userinfo'

export default {
  name: 'Profile',
  components: { Userinfo, Account, UserCard },
  data() {
    return {
      user: {},
      activeTab: 'userinfo'
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'username',
      'sex',
      'phone',
      'email',
      'avatar'
    ])
  },
  created() {
    this.getUser()
  },
  methods: {
    getUser() {
      this.user = {
        name: this.name,
        username: this.username,
        sex: this.sex,
        phone: this.phone,
        email: this.email,
        avatar: this.avatar
      }
    }
  }
}
</script>
